package com.dks.repository.impl.publicCompoment;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.dks.businessUtil.QsMailUtil;
import com.dks.dto.publicCompoment.PublicAttentionDto;
import com.dks.enumeration.PublicAttentionEntityType;
import com.dks.mapper.PublicAttentionMapper;
import com.dks.models.QsMail;
import com.dks.models.publicCompoment.PublicAttention;
import com.dks.repository.IPublicAttentionRepository;
import com.dks.result.*;
import com.dks.vo.publicCompoment.PublicAttentionUserVo;

@Repository
public class PublicAttentionRepository implements IPublicAttentionRepository {

    @Autowired
    private PublicAttentionMapper publicAttentionMapper;

    /**
     * 关注/取消关注
     */
    @Override
    public ResultModel<PublicAttention> attention(PublicAttentionDto publicAttentionDto) {
        PublicAttention publicAttention = new PublicAttention();
        publicAttention.setAttentionEntityType(publicAttentionDto.getAttentionEntityType().name());
        publicAttention.setAttentionEntityId(publicAttentionDto.getAttentionEntityId());
        publicAttention.setCreateUserId(publicAttentionDto.getUserId());
        if (publicAttentionDto.getAttentionStatus().isJudge()){
            //关注
            publicAttentionMapper.addAttention(publicAttention);

            QsMail qsMail = new QsMail(publicAttentionDto.getUserId(), 8, "", "回复了您的评论，快去看看吧", publicAttentionDto.getAttentionEntityId());
            QsMailUtil qsMailUtil = new QsMailUtil();
            qsMailUtil.insertQsMail(qsMail);
        }else{
            //取消关注
            publicAttentionMapper.removeAttention(publicAttention);
        }
        return Result.makeResult(ResultInfo.SUCCESS);
    }


    /**
     * 获取当前用户关注的用户列表
     * @author evan
     */
    @Override
    public ResultModel<List<PublicAttentionUserVo>> getMeAttention(Long userId, PublicAttentionEntityType publicAttentionEntityType) {
        List<PublicAttentionUserVo> userList = publicAttentionMapper.getMeAttention(userId,
                publicAttentionEntityType == null? null : publicAttentionEntityType.name());
        return Result.makeResult(ResultInfo.SUCCESS, userList);
    }

    /**
     * 获取关注当前用户的用户列表
     * @author evan
     */
    @Override
    public ResultModel<List<PublicAttentionUserVo>> getAttentionMe(Long userId, PublicAttentionEntityType userType, PublicAttentionEntityType publicAttentionEntityType) {
        List<PublicAttentionUserVo> userList = publicAttentionMapper.getAttentionMe(userId, userType.name(),
                publicAttentionEntityType == null? null : publicAttentionEntityType.name());
        return Result.makeResult(ResultInfo.SUCCESS, userList);
    }

}
